home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5914 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: solon.com!not-for-mail
  2. From: mcv@pi.net (Miguel Carrasquer Vidal)
  3. Newsgroups: comp.lang.c.moderated,comp.lang.c
  4. Subject: Re: HELP IN WRITING MY FIRST PROGRAM ASSINGMENT
  5. Date: 21 Feb 1996 17:58:01 -0600
  6. Organization: Planet Internet
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4ggbi9$83k@solutions.solon.com>
  10. References: <3127dd4f.19010083@news.planet.net> <3127FF7A.6442C3B8@eden.com> <4gfhkj$3p8@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: Forte Free Agent 1.0.82
  13.  
  14. seebs@solutions.solon.com (Peter Seebach) wrote:
  15.  
  16. > [you know what you coded]
  17. >
  18. >$ sorter < foo
  19. >   1    2    3    4    5    6    7    8    9   10
  20. >  11   12   13   14   15   16   17   18   19   20
  21. >  21   22   23   24   25   26   27   28   29   30
  22. >  31   32   33   34   35   36   37   38   39   40
  23. >  41   42   43   44   45   46   47   48   49   50
  24. >  51   52   53   54   55   56   57   58   59   60
  25. >  61   62   63   64   65   66   67   68   69   70
  26. >  71   72   73   74   75   76   77   78   79   80
  27. >  81   82   83   84   85   86   87   88   89   90
  28. >  91   92   93   94   95   96   97   98   99  100
  29.  
  30. > [...]
  31. >
  32. >Folks: If there appear to be mistakes in this code, *email me before posting*.
  33.  
  34. Well I'm posting anyway :-)
  35. [you may put c.l.c back in the header if you like]
  36.  
  37. I tried it (using Borland C 4.5 large model), and it didn't work.  
  38.  
  39. Output:
  40.  
  41.   50    1   75   94   97   88   35   52   76    4
  42.   34    6   53    7    5   54   77    8   67   11
  43.   10   89   55   56   78   12    9   14   57   15
  44.   13   58   79   16   33   96   98   92    3   68
  45.   84   36    2   38   69   39   37   70   85   40
  46.   51   26   63   27   25   82   91   64   24   65
  47.   29   30   28   83   31   66   62   43   42   93
  48.   71   72   86   44   41   20   60   21   80   22
  49.   61   23   90   46   73   47   45   18   59   19
  50.   17   74   87   81   95   48   32   49   99  100
  51.  
  52.  
  53. I even recompiled the library function qsort with all references to
  54. "near pascal Exchange()" exchanged to "extern swap()", still no go...
  55.  
  56.  
  57. I wonder what my qsort() is doing wrong?
  58.  
  59. [Of course it works if I do:
  60.  
  61. /* compiler insisted I use `const' here... */
  62. int cmp(const void *a, const void *b) {
  63.         if (*(int *)a < *(int *)b) return -1;
  64.         if (*(int *)a > *(int *)b) return 1;
  65.         else return 0;
  66. }
  67.  
  68. and never touch swap(), but that's not nearly as much fun...]
  69.  
  70.  
  71. [but the whole point was that, sorting an array by address is legal, but
  72.  does nothing.  cmp was *intentionally* lying through its teeth, so
  73.  qsort would be a noop.  swap(), as correctly pointed out, is never
  74.  called... It was in there because I was going to use my own quicksort,
  75.  before I realized the stdlib one would work. -mod]
  76.  
  77. ==
  78. Miguel Carrasquer Vidal                     ~ ~
  79. Amsterdam                   _____________  ~ ~
  80. mcv@pi.net                 |_____________|||
  81.  
  82. ========================== Ce .sig n'est pas une .cig
  83.